//
//  GradientHelper.m
//  XMJJ_zml
//
//  Created by 杨何华 on 2025/5/13.
//

#import "GradientHelper.h"

@implementation GradientHelper
+ (CAGradientLayer *)createGradientWithFrame:(CGRect)frame
                                   startColor:(UIColor *)startColor
                                     endColor:(UIColor *)endColor {
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = frame;
    
    // 设置渐变颜色（从顶部到底部）
    gradientLayer.colors = @[(id)startColor.CGColor, (id)endColor.CGColor];
    
    // 设置渐变方向（0.0 到 1.0 表示从上到下）
    gradientLayer.startPoint = CGPointMake(0.0, 0.0);
    gradientLayer.endPoint = CGPointMake(0.0, 1.0);
    
    return gradientLayer;
}

+ (UIView *)createHorizontalGradientViewWithFrame:(CGRect)frame
                                        startColor:(UIColor *)startColor
                                          endColor:(UIColor *)endColor {
    UIView *gradientView = [[UIView alloc] initWithFrame:frame];
    
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame = gradientView.bounds;
    
    // 设置水平渐变颜色（从左到右）
    gradientLayer.colors = @[(id)startColor.CGColor, (id)endColor.CGColor];
    gradientLayer.startPoint = CGPointMake(0.0, 0.5);
    gradientLayer.endPoint = CGPointMake(1.0, 0.5);
    
    [gradientView.layer insertSublayer:gradientLayer atIndex:0];
    
    return gradientView;
}

@end
